using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Super
{
	[RequireComponent(typeof(TextMeshProUGUI))]
	public class ClickRichText : MonoBehaviour, IPointerClickHandler
	{
		private TextMeshProUGUI text;

		/// <summary>
		/// lineid����  
		/// methodBox�о�̬�����ķ�������string���������»��߷ָ�
		/// ���磺HangScript_SavePrefab_AName_GO_Name
		/// </summary>
		/// <param name="eventData"></param>
		public void OnPointerClick(PointerEventData eventData)
		{
			if (text == null)
				text = GetComponent<TextMeshProUGUI>();

			int linkIndex = TMP_TextUtilities.FindIntersectingLink(text, Input.mousePosition, DataHelperUtil.GetUICamera());
			if (linkIndex > -1)
			{
				TMP_LinkInfo linkInfo = text.textInfo.linkInfo[linkIndex];
				string[] ID_Info = linkInfo.GetLinkID().Split("_");
				string methodName = ID_Info[0];
				object[] args = ID_Info.Skip(1).ToArray();
				typeof(MethodCore).GetMethod(methodName).Invoke(null, args);
			}
		}
	}

}
